package com.jd.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangshuping
 * @version 1.0
 * @date 2021/12/23 9:55
 */
@RestController
@RequestMapping("/sr")
public class SentinelResourceTestController {

    @GetMapping("/testBlockHandler")
    @SentinelResource(value = "testBlockHandler", blockHandler = "testBlockHandlerFallback")
    public String testBlockHandler() {
        return "blockHandler";
    }

    public String testBlockHandlerFallback(BlockException exception) {
        return "testBlockHandlerFallback";
    }

    @GetMapping("/testClassBlockHandler")
    @SentinelResource(value = "testClassBlockHandler", blockHandlerClass = CustomerBlockHandler.class, blockHandler = "handlerException1")
    public String testClassBlockHandler() {
        return "testClassBlockHandler";
    }

}
